const base_url = 'https://sz.vvv5g.com/api/wanlshop/'
const image_url = 'https://sz.vvv5g.com'
export const img_url = "https://sz.vvv5g.com"
export const request = (options) => {
	let userInfo = uni.getStorageSync("userInfo")
	if (options.url == 'user/phoneDecrypt' && uni.getStorageSync("tempUserInfo")) {
		userInfo = uni.getStorageSync("tempUserInfo")
	}
	return new Promise((resolve, reject) => {
		uni.request({
			url: base_url + options.url,
			header: {
				'Content-Type': 'application/json',
				'token': userInfo.token || ''
			},
			method: options.method || 'GET',
			data: options.data || {},
			timeout: 30000,
			dataType: 'json',
			success: (res) => {
				if (res.data.code == 401) {
					uni.showToast({
						title: '请先登录在操作',
						icon: 'none',
						duration: 1000
					});
					setTimeout(() => {
						uni.navigateBack({})
					}, 1000);
				} else if (res.data.code == 404) {
					uni.showToast({
						title: '',
						icon: 'none',
						duration: 1000
					});
				}
				resolve(res)
			},
			fail: (err) => {
				uni.hideLoading();
				uni.showToast({
					title: "请求失败！",
					icon: 'error'
				})
				reject(err)
			}
		})
	})
}